/**
 * 全局状态管理
 */
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default {
    state: {
        //菜单
        menuList: [],
        //权限
        authority: [],
        //路由状态
        hasRoute: false,
        //动态标签
        editableTabsValue: '2',
        editableTabs: [{
            title: '首页',
            name: 'Index',
        }],
    },
    mutations: {
        //添加菜单
        setMenuList(state, menus) {
            state.menuList = menus
        },
        //添加权限
        setAuthList(state, auths) {
            state.authority = auths
        },
        //改变路由状态
        changeHasRouteStatus(state, hasRoute) {
            state.hasRoute = hasRoute
            sessionStorage.setItem("hasRoute", hasRoute)
        },
        //添加动态标签页
        addTab(state, tab) {
            let index = state.editableTabs.findIndex(e => e.name === tab.name)
            if (index === -1) {
                state.editableTabs.push({
                    title: tab.title,
                    name: tab.name,
                });
            }
            state.editableTabsValue = tab.name;
        },
        resetState: (state) => {
            state.menuList = []
            state.authority = []

            state.hasRoute = false

            state.editableTabsValue = 'Index'
            state.editableTabs = [{
                title: '首页',
                name: 'Index',
            }]


        }
    },
    actions: {}
}
